// 对象的深拷贝
function cloneDeepObj(obj) {
  // 浅拷贝子节点
  let handleChild = (child) => {
    if (typeof child === 'object') {
      if (Array.isArray(child)) { // 数组
        return [...child];
      } else if (child) { // 对象
        return { ...child };
      } else { // null
        return child;
      }
    } else { // 值类型
      return child;
    }
  };

  let arr = [];
  let target = { result: obj };
  let current = target;
  let temp = null;
  if (typeof current === 'object') {
    if (Array.isArray(current)) { // 数组
      current.forEach((item, index) => {
        let child = handleChild(item);
        current[index] = child;
        arr.push(child);
      });
    } else if (current) { // 对象
      let objKeys = Object.keys(current);
      objKeys.forEach(key => {
        let child = handleChild(current[key]);
        current[key] = child;
        arr.push(child);
      });
    } else { // null
      temp = current;
    }
  }
  current = arr.shift();
  return target.result;
}
